//
//  ZJRoomModelCell.m
//  英伦府邸
//
//  Created by IOS_DEVELOPER on 2017/8/10.
//  Copyright © 2017年 英伦府邸. All rights reserved.
//

#import "ZJRoomModelCell.h"

@implementation ZJRoomModelCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.topImg.clipsToBounds = YES;
}

-(void)setModel:(ZJRoomMoel *)model{
    _model = model;
    [self.topImg sd_setImageWithURL:[NSURL URLWithString:_model.pic_url] placeholderImage:[UIImage imageNamed:kDefaultImageName]];
    self.mainTitle.text = _model.model_name;
//    self.subTitle.text = [NSString stringWithFormat:@"%@ | 建面:%@㎡ | 套内:%@㎡",_model.layout,_model.house_area,_model.actual_area];
    if ([self.model.actual_area integerValue] == 0) {
         self.subTitle.text = [NSString stringWithFormat:@"%@ | 建面:%@㎡",_model.layout,_model.house_area];
    }else{
         self.subTitle.text = [NSString stringWithFormat:@"%@ | 建面:%@㎡ | 套内:%@㎡",_model.layout,_model.house_area,_model.actual_area];
    }
    self.DTTitle.text = _model.tags;
    
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:8];
    NSAttributedString *string = [[NSAttributedString alloc] initWithString:self.DTTitle.text attributes:@{NSForegroundColorAttributeName : self.DTTitle.textColor, NSParagraphStyleAttributeName: paragraphStyle}];
    
    self.DTTitle.attributedText = string;
    
    CGFloat imgHeight = (SCREEN_WIDTH - 16) * [_model.pic_ratio floatValue];
    
    self.DTTitle.isAttributedContent = YES;
    self.bgView.sd_layout.leftSpaceToView(self.contentView, 8).topSpaceToView(self.contentView, 8).rightSpaceToView(self.contentView, 8).autoHeightRatio(0);
    self.topImg.sd_layout.leftSpaceToView(self.bgView, 0).topSpaceToView(self.bgView, 0).rightSpaceToView(self.bgView, 0).heightIs(imgHeight);
    self.mainTitle.sd_layout.leftSpaceToView(self.bgView, 8).topSpaceToView(self.topImg, 8).rightSpaceToView(self.bgView, 0).autoHeightRatio(0);
    self.subTitle.sd_layout.leftSpaceToView(self.bgView, 8).topSpaceToView(self.mainTitle, 8).rightSpaceToView(self.bgView, 0).autoHeightRatio(0);
    self.DTTitle.sd_layout.leftSpaceToView(self.bgView, 8).topSpaceToView(self.subTitle, 8).rightSpaceToView(self.bgView, 0).autoHeightRatio(0);
    
    [self.bgView setupAutoHeightWithBottomView:self.DTTitle bottomMargin:8];
    [self setupAutoHeightWithBottomViewsArray:@[self.bgView,self.DTTitle,self.topImg,self.mainTitle,self.subTitle] bottomMargin:0];
}
@end
